Repository navigation
cuda: smaller KV tile for the 8-column MMA flash attention config (head size 256) - #308
Merged
Merged
Conversation
…Ampere/Ada (head size 256) With nbatch_fa 64 the kernel flash_attn_ext_f16<256,256,1,8> (one query, GQA 6) fits only 2 blocks per SM because of shared memory and reaches 58% of the DRAM bandwidth at 120k keys. nbatch_fa 32 fits 5 blocks per SM (84% DRAM). RTX 4070, Bonsai 2 27B, q4_0 K/V, one query, per layer: 32k keys 122 -> 87 us, 120k keys about 540 -> 370 us. Decode without speculative decoding: 32k 54.4 -> 56.4 tok/s, 120k 41.2 -> 46.0 tok/s. No change with 2-3 queries (different config), no change at depth 0. test-backend-ops FLASH_ATTN_EXT: 3006/3006 passed. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
bri-prism
reviewed
Oct 23, 2026
bri-prism
left a comment
Collaborator
There was a problem hiding this comment.
Agent review: posted by the maintainer's coding agent at their request.
H200 data point (sm_90, CUDA 12.8), this diff applied to prism 73bfe6c:
- test-backend-ops: FLASH_ATTN_EXT with hsk=256, 372/372.
- llama-bench: Ternary-Bonsai-2-9B (head size 256, GQA 4), tg64 at depth 0, 16k and 32k, f16 and q8_0 K/V, alternating base/PR, 2 pairs each. No change:
- f16: 276 / 260 / 242 tok/s with or without the patch.
- q8_0: 267 / 245 / 223 tok/s with or without the patch.
This is consistent with your note: on Hopper, with 228 KB of shared memory per SM, occupancy isn't the limit. And without #307, quantized K/V with GQA takes the vector kernel. So the change looks neutral there. I can't check the 27B GQA 6 shape on Ada from here.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
For head size 256 with 8 columns (1 query, GQA 6), the Ampere/Ada MMA config uses
nbatch_fa64. The shared memory then allows only 2 blocks per SM (92 blocks on a 4070, 58 % of DRAM bandwidth at 120k keys). Withnbatch_fa32, 5 blocks per SM fit (228 blocks, 84 % DRAM).RTX 4070, q4_0 K/V, 1 query, per layer: 32k keys 122 -> 87 us; 120k keys about 540 -> 370 us. Model, decode without speculative decoding (Ternary-Bonsai-2-27B): 32k 54.4 -> 56.4 tok/s, 120k 41.2 -> 46.0 tok/s. No change for 2-3 queries (other config) and none at depth 0.
Additional information
ggml_cuda_fattn_mma_get_config_ampere. test-backend-ops FLASH_ATTN_EXT 3006/3006 (3006 includes 12 local extra cases, not in this PR).nstages1 (slower), smaller K/V tiles (not implemented with 2 stages), 64 threads for the 32-column config (within noise).nbatch_fais the number of KV rows per softmax rescaling, so a different value changes how the online softmax is grouped and rounded (the comment above the config says it should only affect speed, which holds up to rounding). Numbers below.Test results
-DGGML_CUDA=ON -DCMAKE_CUDA_ARCHITECTURES=89.prismat88c4bc60b; the four commits since (SYCL, WebGPU andcuda: fused FWHT quantizer for 64-wide warps (#303)) do not touch this code path. The branch is rebased on2459f68b5, builds, andtest-backend-opswas repeated on it.n-max 2(3 queries use a different config) and none at depth 0.test-backend-ops test -b CUDA0 -o FLASH_ATTN_EXT: 2994/2994 passed on the rebased branch (CUDA0 against CPU); on the earlier base 3006/3006 including 12 local extra cases that are not part of this PR.Requirements